local weichiri = fk.CreateSkill{
  name = "lzsj__weichiri",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["lzsj__weichiri"] = "为炽日",
  ["@lzsj__weichiri"] = "<font color=\"#E8251E\"><b>为炽日</b></font>",
  [":lzsj__weichiri"] = "锁定技，你视为拥有<a href=':ty_ex__yicong'>“义从”</a>，当你造成伤害后，<a href=':ty_ex__yicong'>“义从”</a>描述中距离数字+1；"..
  "一轮开始时，若你不在所有其他角色的攻击范围内，你移动场上至多三张红色牌至你并回复等量体力，然后此技能效果改为其他角色受到的火焰和光照伤害+1。",
  [":ty_ex__yicong"] = "锁定技，你计算与其他角色的距离-1；若你已损失的体力值不小于2，其他角色计算与你的距离+1。",
  [":lzsj__weichiri_edit"] = "锁定技，其他角色受到的火焰和光照伤害+1。",
  ["#lzsj__weichiri"] = "为炽日：请选择移动牌至你的角色（第%arg次）",

  ["$lzsj__weichiri1"] = "人民仰望的太阳，永不西沉！（인민이 우러러보는 태양은 영원히 지지 않는다!）",
  ["$lzsj__weichiri2"] = "主体的光芒，照亮千里马的前路！（주체의 빛이 천리마의 길을 밝힌다!）",
}

weichiri:addAcquireEffect(function (self, player, is_start)
  player.room:setPlayerMark(player, "@lzsj__weichiri", 1)
end)

weichiri:addEffect("distance", {
  correct_func = function(self, from, to)
    local n = 0
    if from:hasSkill(weichiri.name) and from:getMark("isSun") == 0 then
      n = n - from:getMark("@lzsj__weichiri")
    end
    if to:hasSkill(weichiri.name) and to:getLostHp() >= 2 and to:getMark("isSun") == 0 then
      n = n + to:getMark("@lzsj__weichiri")
    end
    return n
  end,
})

weichiri:addEffect(fk.Damage, {
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(weichiri.name) and player:getMark("isSun") == 0
  end,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "@lzsj__weichiri")
  end,
})

weichiri:addEffect(fk.DamageCaused, {
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(weichiri.name) and player:getMark("isSun") > 0 and data.to ~= player
    and (data.damageType == fk.FireDamage or data.damageType == fk.BrightDamage)
  end,
  on_refresh = function(self, event, target, player, data)
    data:changeDamage(1)
  end,
})

weichiri:addEffect(fk.RoundStart, {
  dynamic_desc = function(self, player)
    local texts = "lzsj__weichiri"
    if player:getMark("isSun") > 0 then
      texts = "lzsj__weichiri_edit"
    end
    return texts
  end,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(weichiri.name) and player:getMark("isSun") == 0 then
      return table.every(player.room:getOtherPlayers(player), function (p) return not p:inMyAttackRange(player) end)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = 0
    for i = 1, 3, 1 do
      local players = table.filter(room:getOtherPlayers(player), function (p) return
        p:canMoveCardsInBoardTo(player, nil, table.filter(p:getCardIds("ej"), function (id)
          return Fk:getCardById(id).color ~= Card.Red end)) end)
      if #players == 0 then break end
      local tos = room:askToChoosePlayers(player, {
        targets = players,
        min_num = 1,
        max_num = 1,
        prompt = "#lzsj__weichiri:::"..i,
        skill_name = weichiri.name,
        cancelable = true,
      })
      if #tos == 0 then
        break
      else
        local cards = table.filter(tos[1]:getCardIds("ej"), function (id)
          return Fk:getCardById(id).color ~= Card.Red
        end)
        room:askToMoveCardInBoard(player, {
          target_one = tos[1],
          target_two = player,
          skill_name = weichiri.name,
          move_from = tos[1],
          exclude_ids = cards,
        })
        n = n + 1
      end
    end
    if n > 0 then
      room:recover{who = player, num = n, skillName = weichiri.name}
    end
    player.room:addPlayerMark(player, "isSun")
    player.room:setPlayerMark(player, "@lzsj__weichiri", 0)
  end,
})

return weichiri